<template>
  <div>
    <page-list :x-uri="uri" :doactions="doactions" :custom-components="customComponents" :search-custom-components="searchCustomComponents" :checkbox-item="false">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs :tabs="tabs" />
        <page-header :content="bankTitle" />
      </template>
      <!-- 页面操作按钮 -->
      <template v-slot:page-button>
        <el-button v-auth="'exam.question.topic.create'" size="mini" type="primary" @click="create">新建题目</el-button>
        <el-button v-auth="'exam.question.topic.create'" size="mini" type="primary" @click="importTopic">导入题目</el-button>
      </template>
      <!-- 多选操作 -->
      <!--    <template v-slot:table-button="scope">
      <el-button size="mini" @click="deletes(scope)" v-auth="'exam.question.topic.delete'">删除</el-button>
    </template> -->
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Tabs from '../tabs';
import Title from '../../topic/components/title.vue';
import LinkPaper from '../../topic/components/link_info.vue';
import SearchBank from '../SearchBank/index.vue';
import PageHeader from '@/components/page-header';
export default {
  components: {
    PageList,
    Tabs,
    PageHeader
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/exam/admin/question/bank/' + this.$route.params.id + '/topics',
      customComponents: {
        title: Title,
        num: LinkPaper
      },
      doactions: [{ title: '详情', callback: this.info }, { title: '编辑', callback: this.edit }, { title: '删除', callback: this.delete }],
      dialogVisible: true,
      searchCustomComponents: {
        bank: SearchBank
      },
      tabs: [
        {
          title: '题库试题管理',
          uri: '/exam/question/bank/' + this.$route.params.id + '/topics',
          meta: {
            permission: 'exam.question.topic.list'
          }
        }
      ],
      bankTitle: this.$localStorage.get('bank_title')
    };
  },
  methods: {
    // 导入试题
    importTopic() {
      this.$router.push({ path: '/exam/question/bank/' + this.$route.params.id + '/import' });
    },
    // 新建
    create: function() {
      this.$router.push({ path: '/exam/question/topic/create' });
    },
    // 详情
    info: function({ row }) {
      this.$router.push({ path: '/exam/question/topic/' + row.id + '/details' });
    },
    // 编辑
    edit: function({ row }) {
      this.$router.push({ path: '/exam/question/topic/' + row.id + '/edit' });
    },
    // 删除
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/exam/admin/question/topic/' + row.id + '/delete',
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
